package cc.sheji.controller;


import cc.sheji.Service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping(value = "/api/v1/pay")
public class WxPayController {


    @Autowired
    PayService payService;




    @RequestMapping(value = "/wx")
    Map<String, String> stockCouponsReceiveCallback(@RequestBody String requestBody,
                                                    @RequestHeader("Wechatpay-Serial") String wechatpaySerial,
                                                    @RequestHeader("Wechatpay-Signature") String wechatpaySignature,
                                                    @RequestHeader("Wechatpay-Timestamp") String wechatpayTimestamp,
                                                    @RequestHeader("Wechatpay-Nonce") String wechatpayNonce) {

        try {
            System.out.println("boody:"+requestBody);
            payService.stockCouponsReceiveCallback(requestBody,wechatpaySerial,wechatpaySignature,wechatpayTimestamp,wechatpayNonce);
            HashMap<String, String> map = new HashMap<>();
            map.put("return_code", "SUCCESS");
            map.put("return_msg", "OK");
            return map;
        } catch (Exception e) {
        }
        HashMap<String, String> map = new HashMap<>();
        map.put("return_code", "FAIL");
        map.put("return_msg", "");
        return map;
    }


}
